﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BookingSystemModel;
using BookingSystemDAL;
using BookingSystemBLL;
using System.Data;

public partial class register : System.Web.UI.Page
{
    private user User =  new user();
    //private UserBLL userbll = new UserBLL();
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Button_ok_Click(object sender, EventArgs e)
    {

        try
        {
            foreach (Control x in this.Controls)
            {
                if (x is System.Web.UI.WebControls.TextBox && ((System.Web.UI.WebControls.TextBox)x).Text == "")
                {
                    Response.Write("<script language=javaScript>alert('不能为空');</script>");
                }
                
            }
            if(this.PassWord.Text!=this.ConfirmPassword.Text)
                Response.Write("<script language=javaScript>alert('两次输入密码不一致');</script>");
                SetTxetToReader();
                    UserBLL.AddUser(User);
                    Response.Write("<script language=javaScript>alert('注册成功！');</script>");
                    Session["username"] = this.UserName;
                    Response.Redirect("MainPage.aspx");               
        }
        catch (System.Exception ex)
        {
            throw (ex);
        }               
    }
    private void SetTxetToReader()
    {
        User.UserNickName = this.UserName.Text;
        User.Pwd = this.PassWord.Text;
        User.UserName = this.Realname.Text;
        User.UserIDNumber =this.UserIDCar.Text;
        User.Sex = this.Sex.Text;
        User.Phone = this.CellPhone.Text;
        User.Email = this.Email.Text;
        User.Address = this.Address.Text;
        User.RegisterTime = DateTime.Now;
    }


    //重置代码实现方法
    private void ResetButton(Control c)
    {
        if (c.Controls!=null)
        {
            foreach (Control x in c.Controls)
            {
                if (x is System.Web.UI.WebControls.TextBox)
                {
                    ((System.Web.UI.WebControls.TextBox)x).Text = "";
                }

                ResetButton(x);
            }
        }
    }
    protected void Button_reset_Click(object sender, EventArgs e)
    {
        this.ResetButton(this);
    }
    
}